﻿using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using QuanLyTuyenSinh.Base;
using QuanLyTuyenSinh.DataLayer;

namespace QuanLyTuyenSinh.BussinessLayer
{
    public class Priority
    {
        private readonly DataConfig dataConfig;
        private DataTable dtTable;

        public Priority()
        {
            dataConfig = new DataConfig(frmLoading.Servername, frmLoading.UserName, frmLoading.Pass);
        }

        public int Id { get; set; }
        public string PriorityDisplay { get; set; }
        public string PriorityName { get; set; }
        public decimal PriorityNumber { get; set; }

        public int Insert(Priority obj)
        {
            int result = 0;
            string sql = string.Format("INSERT INTO Priority(PriorityDisplay,PriorityName,PriorityNumber) values (N'{0}', N'{1}', '{2}')", obj.PriorityDisplay, obj.PriorityName, obj.PriorityNumber);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Update(Priority obj)
        {
            int result = 0;
            string sql = string.Format("UPDATE Priority SET PriorityDisplay=N'{0}', PriorityName=N'{1}', PriorityNumber= '{2}' WheRE " +
                                       "Id= N'{3}'", obj.PriorityDisplay, obj.PriorityName, obj.PriorityNumber, obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Delete(Priority obj)
        {
            int result = 0;
            string sql = string.Format("DELETE Priority  Where id= N'{0}'", obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
    }
}